package leading;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class WaLyh {
	public static void main(String[] args) {
		int[] c = howLong("2011-05-01 18:06","2012-02-01 18:12");
		System.out.println("认识了"+c[0]+"天"+c[1]+"小时"+c[2]+"分钟");
	}
	
	public static int[] howLong(String d1,String d2){
		int[] dArr = new int[3];
		long nd = 1000*24*60*60;//一天的毫秒数
		long nh = 1000*60*60;//一小时的毫秒数
		long nm = 1000*60;//一分钟的毫秒数
		int tDay = 0;
		int tHour = 0;
		int tMin = 0;
		SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		GregorianCalendar gc = new GregorianCalendar();
		try {
			Date tDate1 = sf.parse(d1);
			Date tDate2 = sf.parse(d2);
			
			//相减得到相差的毫秒值
			long tTimeMillion = tDate2.getTime() - tDate1.getTime();
			tDay = (int) (tTimeMillion/nd);
			tHour = (int) (tTimeMillion%nd/nh);
			tMin = (int)(tTimeMillion%nd%nh/nm);
			dArr[0] = tDay;
			dArr[1] = tHour;
			dArr[2] = tMin;
			
/*			gc.setTime(tDate1);
			a = gc.get(Calendar.DAY_OF_YEAR);
			System.out.println(a);
			gc.setTime(tDate2);
			b = gc.get(Calendar.DAY_OF_YEAR);
			System.out.println(b);*/
		} catch (Exception e) {
			e.printStackTrace();
		}
		return dArr;
	} 
}
